package com.bootdo.system.controller;


import com.bootdo.system.domain.FrontuserDO;
import com.bootdo.system.domain.QuestionDO;
import com.bootdo.system.service.QuestionService;
import com.bootdo.system.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

@Controller
public class QuestionController extends BaseController{

    @Autowired
    private QuestionService questionService;

    @GetMapping("/question")
    public String question(HttpServletRequest request){

        List<QuestionDO> questionDOS = questionService.getUserQuestionList(getUserId(request));
        request.setAttribute("questionDOS",questionDOS);


        List<QuestionDO> huifuQuestionList = questionService.getHuifuQuestionList(getUserId(request));
        request.setAttribute("huifuQuestionList",huifuQuestionList);

        return  "question";
    }

    @ResponseBody
    @PostMapping("/question/save")
    public R SaveQuestion(QuestionDO questionDO,HttpServletRequest request){

        questionDO.setUserid(getUserId(request));
        questionDO.setCreatetime(new Date());
        int save = questionService.save(questionDO);
        if(save>0){
            return R.ok();
        }

        return R.error("保存失败");
    }
}
